/**
 * Created by Jie on 2017/4/19.
 */
const router = require('koa-router')();
const server = require('../mosca');
router.get('/push', async(ctx, next) => {
    await ctx.render('push', {});
});
router.post('/pushMessage', async(ctx, next) => {
    let {payload, topic} = ctx.request.body;
    let msg = {
        topic: topic,
        payload: payload,
        qos: 0,
        retain: false
    };
    await server.publish(msg, () => {
        console.log('push success');
    });
    ctx.body = 'push success';
});
module.exports = router;